package com.zcy.gift.strategy.impl;

import com.zcy.gift.strategy.IShopCarDataSyncKeysGroupStrategy;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author lucker
 * @date 2024/2/22 11:40
 */
public class ShopCarDataSyncKeysGroupByHashCode implements IShopCarDataSyncKeysGroupStrategy {
    private int groupNum = 100;

    public ShopCarDataSyncKeysGroupByHashCode() {

    }

    public ShopCarDataSyncKeysGroupByHashCode(int groupNum) {
        this.groupNum = groupNum;
    }

    @Override
    public Map<Integer, List<String>> group(Set<String> keys) {
        return keys.stream().collect(Collectors.groupingBy(x -> x.hashCode() % this.groupNum));
    }
}
